<?php

namespace app\api\controller\shop;

use addons\epay\library\Service;
use app\admin\model\Article;
use app\admin\model\Articletype;
use app\admin\model\City;
use app\admin\model\Shop;
use app\admin\model\Shopcharge;
use app\admin\model\Shopchargeconfig;
use app\admin\model\Shopjoin;
use app\admin\model\Shopks;
use app\admin\model\Shopmeituan;
use app\admin\model\Shoporder;
use app\admin\model\Shoporderprofit;
use app\admin\model\Shoproom;
use app\admin\model\Shoptuan;
use app\admin\model\Tuanorder;
use app\admin\model\Userbalance;
use app\admin\model\Usermeituancode;
use app\admin\model\Userorderprofit;
use app\admin\model\Usertuan;
use app\admin\model\Userweixin;
use app\api\service\KsService;
use app\api\service\MtUtil;
use app\common\controller\Api;
use app\common\library\Ems;
use app\common\library\Sms;
use fast\Http;
use fast\Random;
use think\Config;
use think\Validate;
use Yansongda\Pay\Pay;

/**
 */
class Invest extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = '*';
    protected $appKey = "";
    protected $secret = "";

    public function _initialize()
    {
        parent::_initialize();

    }


    public function summary ()
    {
        $shopId = $this->request->param('shop_id');

        $shopOrderModel = new Shoporder();

        $totalAmount = $shopOrderModel->where('shop_id',$shopId)->where('status','in',['payed','done','doing'])->sum('amount');
        $payAmount = $shopOrderModel->where('shop_id',$shopId)->where('status','in',['payed','done','doing'])->sum('pay_amount');

        $ret = array();
        $ret['totalAmount'] = $totalAmount;
        $ret['payAmount'] = $payAmount;

        $dateList = array();
        for($i=0;$i<12;$i++)
        {
            $obj = array();
            $date = date('Y-m',strtotime('-'.$i.'month'));//包含本月
            $endDate = strtotime("-1 day", strtotime(date('Y-m',strtotime('-'.($i-1).'month'))."-01"));

            $startTime = strtotime($date."-01 00:00:00");
            $endTime = strtotime(date("Y-m-d",$endDate)." 23:59:59");
            $obj['date'] = $date;
            $obj['startTime'] = $startTime;
            $obj['endTime'] = $endTime;
            $obj['startDate'] = date("Y-m-d",$startTime);
            $obj['endDate'] =  date("Y-m-d",$endTime);
            $totalAmount = $shopOrderModel->where('shop_id',$shopId)->where('create_time','>=',$startTime)->where('create_time',"<=",$endTime)->where('status','in',['payed','done','doing'])->sum('amount');
            $obj['amount'] = $totalAmount;
            $dateList[] = $obj;
        }

        $ret['date'] = $dateList;

        $this->success('',$ret);
    }



}
